class Solution {
    public String countAndSay(int n) {
        return fun(n);
    }
    public String fun(int n) {
        if (n == 1) {
            return "1";
        }
        return count(fun(n - 1));
    }
    public String count(String s) {
        char[] arr = s.toCharArray();
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            int t = i;
            while (i < arr.length - 1 && arr[i] == arr[i + 1]) {
                i++;
            }
            str.append(i - t + 1);
            str.append(arr[i]);
        }
        return str.toString();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        //System.out.println(solution.count("21"));
        System.out.println(solution.countAndSay(4));
    }
}